﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using FrameEngine;

namespace wpfUI.CommandUI
{
    public class CommandUIOfMenuItem : MenuItem, ICommandUI
    {

        private ICommand _command = null;


        /// <summary>
        /// RibbonMenuItem 命令UI
        /// </summary>
        /// <param name="pCommand"></param>
        public CommandUIOfMenuItem(ICommand pCommand):this()
        {
            this._command = pCommand;
            pCommand.SetCommandUI(this);
        }
        public CommandUIOfMenuItem()
        {
            IsCheckable = true;
            try
            {
                object style = Application.Current.FindResource("MenuItemStyle");
                Style = style as System.Windows.Style;
            }
            catch
            {
            }
        }

        public ICommand GetCommand()
        {
            return this._command;
        }

        public void SetCaption(string pCaption)
        {
            this.Header = pCaption;
        }

        public void SetCheckedState(bool pIsCheced)
        {
            this.IsChecked = pIsCheced;
        }

        public void SetEnabledState(bool pIsEnabled)
        {
            this.IsEnabled = pIsEnabled;
        }

        public void SetImageSource(ImageSource pImageSource)
        {
            this.Icon = new Image() {Source = pImageSource};
        }

        public void SetToolTip(string pToolTip)
        {
            this.ToolTip = pToolTip;
        }

        public void SetVisibleState(bool IsVisible)
        {
            if (IsVisible)
            {
                this.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                this.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
        protected override void OnClick()
        {
            base.OnClick();
            _command.OnClick();
        }


    }
}
